/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.eng.scc.core.schema.fetcher;

import com.eng.scc.core.data.Device;
import com.eng.scc.core.db.Database;
import com.eng.scc.core.db.Fetcher;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 * @author Rafael
 */
public class DeviceFetcher implements Fetcher<Device>
{

//    Fields.ID + COMMA +
//    Fields.REF_VEHICLE + COMMA +
//    Fields.SERIAL + COMMA +
//    Fields.DESCRIPTION + COMMA +
//    Fields.DT_INSTALLATION +
    @Override
    public Device fetch( ResultSet ps ) throws Exception
    {
        Device h = new Device();
        h.setId( ps.getInt( 1 ) );
        h.setVehicleId( ps.getInt( 2 ) );
        h.setSerial( ps.getInt( 3 ) );
        h.setDescription( ps.getString( 4 ) );
        h.setInstallationDate( ps.getDate( 5 ) );
        h.setStatus( ps.getInt( 6 ) );
        
        return h;
    }

    @Override
    public void insert( Device value, PreparedStatement ps ) throws Exception
    {
        value.setId( Database.getInstance().nextID( "core_devices" ) );
        
        ps.setInt( 1, value.getId() );
        ps.setInt( 2, value.getVehicleId() );
        ps.setInt( 3, value.getSerial() );
        ps.setString( 4, value.getDescription() );
        ps.setDate( 5, value.getInstallationDate() );
        ps.setInt( 6, value.getStatus() );
    }

    @Override
    public void update( Device value, PreparedStatement ps ) throws Exception
    {
        ps.setInt( 1, value.getVehicleId() );
        ps.setInt( 2, value.getSerial() );
        ps.setString( 3, value.getDescription() );
        ps.setDate( 4, value.getInstallationDate() );
        ps.setInt( 5, value.getStatus() );
        ps.setInt( 6, value.getId() );
    }
    
}
